home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / (Extra Support) / CIncludes / Threads.h
Text File  |  1995-02-17  |  6KB  |  179 lines

  1. /*
  2.      File:        Threads.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a2+  unofficial build.  Thursday, October 6, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __THREADS__
  18. #define __THREADS__
  19.  
  20.  
  21. #ifndef __ERRORS__
  22. #include <Errors.h>
  23. #endif
  24. /*    #include <ConditionalMacros.h>                                */
  25.  
  26. #ifndef __MEMORY__
  27. #include <Memory.h>
  28. #endif
  29. /*    #include <Types.h>                                            */
  30. /*    #include <MixedMode.h>                                        */
  31.  
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35.  
  36. #if GENERATINGPOWERPC
  37. #pragma options align=mac68k
  38. #endif
  39.  
  40. #ifdef __CFM68K__
  41. #pragma lib_export on
  42. #endif
  43.  
  44. typedef unsigned short ThreadState;
  45.  
  46.  
  47. enum {
  48.     kReadyThreadState            = 0,
  49.     kStoppedThreadState            = 1,
  50.     kRunningThreadState            = 2
  51. };
  52.  
  53. /* Error codes have been meoved to Errors.(pah) */
  54. /* Thread environment characteristics */
  55. typedef void *ThreadTaskRef;
  56.  
  57. /* Thread characteristics */
  58. typedef unsigned long ThreadStyle;
  59.  
  60.  
  61. enum {
  62.     kCooperativeThread            = 1L << 0,
  63.     kPreemptiveThread            = 1L << 1
  64. };
  65.  
  66. /* Thread identifiers */
  67. typedef unsigned long ThreadID;
  68.  
  69.  
  70. enum {
  71.     kNoThreadID                    = 0,
  72.     kCurrentThreadID            = 1,
  73.     kApplicationThreadID        = 2
  74. };
  75.  
  76. /* Options when creating a thread */
  77. typedef unsigned long ThreadOptions;
  78.  
  79.  
  80. enum {
  81.     kNewSuspend                    = (1 << 0),
  82.     kUsePremadeThread            = (1 << 1),
  83.     kCreateIfNeeded                = (1 << 2),
  84.     kFPUNotNeeded                = (1 << 3),
  85.     kExactMatchThread            = (1 << 4)
  86. };
  87.  
  88. /* Information supplied to the custom scheduler */
  89. struct SchedulerInfoRec {
  90.     unsigned long                    InfoRecSize;
  91.     ThreadID                        CurrentThreadID;
  92.     ThreadID                        SuggestedThreadID;
  93.     ThreadID                        InterruptedCoopThreadID;
  94. };
  95. typedef struct SchedulerInfoRec SchedulerInfoRec;
  96.  
  97. typedef SchedulerInfoRec *SchedulerInfoRecPtr;
  98.  
  99. /*
  100.     The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  101.     of differences between 680x0 and PowerPC runtime architectures with regard to
  102.     the implementation of the Thread Manager.
  103.  */
  104. /* Prototype for thread's entry (main) routine */
  105. typedef void *voidPtr;
  106.  
  107. typedef pascal voidPtr (*ThreadEntryProcPtr)(void *threadParam);
  108. /* Prototype for custom thread scheduler routine */
  109. typedef pascal ThreadID (*ThreadSchedulerProcPtr)(SchedulerInfoRecPtr schedulerInfo);
  110. /* Prototype for custom thread switcher routine */
  111. typedef pascal void (*ThreadSwitchProcPtr)(ThreadID threadBeingSwitched, void *switchProcParam);
  112. /* Prototype for thread termination notification routine */
  113. typedef pascal void (*ThreadTerminationProcPtr)(ThreadID threadTerminated, void *terminationProcParam);
  114. /* Prototype for debugger NewThread notification */
  115. typedef pascal void (*DebuggerNewThreadProcPtr)(ThreadID threadCreated);
  116. /* Prototype for debugger DisposeThread notification */
  117. typedef pascal void (*DebuggerDisposeThreadProcPtr)(ThreadID threadDeleted);
  118. /* Prototype for debugger schedule notification */
  119. typedef pascal ThreadID (*DebuggerThreadSchedulerProcPtr)(SchedulerInfoRecPtr schedulerInfo);
  120. /* Thread Manager routines */
  121. extern pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
  122.  THREEWORDINLINE(0x303C, 0x0501, 0xABF2);
  123. extern pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
  124.  THREEWORDINLINE(0x303C, 0x0402, 0xABF2);
  125. extern pascal OSErr GetSpecificFreeThreadCount(ThreadStyle threadStyle, Size stackSize, short *freeCount)
  126.  THREEWORDINLINE(0x303C, 0x0615, 0xABF2);
  127. extern pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
  128.  THREEWORDINLINE(0x303C, 0x0413, 0xABF2);
  129. extern pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
  130.  THREEWORDINLINE(0x303C, 0x0414, 0xABF2);
  131. extern pascal OSErr NewThread(ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, void *threadParam, Size stackSize, ThreadOptions options, void **threadResult, ThreadID *threadMade)
  132.  THREEWORDINLINE(0x303C, 0x0E03, 0xABF2);
  133. extern pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
  134.  THREEWORDINLINE(0x303C, 0x0504, 0xABF2);
  135. extern pascal OSErr YieldToThread(ThreadID suggestedThread)
  136.  THREEWORDINLINE(0x303C, 0x0205, 0xABF2);
  137. extern pascal OSErr YieldToAnyThread(void)
  138.  FOURWORDINLINE(0x42A7, 0x303C, 0x0205, 0xABF2);
  139. extern pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
  140.  THREEWORDINLINE(0x303C, 0x0206, 0xABF2);
  141. extern pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
  142.  THREEWORDINLINE(0x303C, 0x0407, 0xABF2);
  143. extern pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  144.  THREEWORDINLINE(0x303C, 0x0508, 0xABF2);
  145. extern pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  146.  THREEWORDINLINE(0x303C, 0x0512, 0xABF2);
  147. extern pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
  148.  THREEWORDINLINE(0x303C, 0x0209, 0xABF2);
  149. extern pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
  150.  THREEWORDINLINE(0x303C, 0x070A, 0xABF2);
  151. extern pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
  152.  THREEWORDINLINE(0x303C, 0x0611, 0xABF2);
  153. extern pascal OSErr ThreadBeginCritical(void)
  154.  THREEWORDINLINE(0x303C, 0x000B, 0xABF2);
  155. extern pascal OSErr ThreadEndCritical(void)
  156.  THREEWORDINLINE(0x303C, 0x000C, 0xABF2);
  157. extern pascal OSErr SetDebuggerNotificationProcs(DebuggerNewThreadProcPtr notifyNewThread, DebuggerDisposeThreadProcPtr notifyDisposeThread, DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
  158.  THREEWORDINLINE(0x303C, 0x060D, 0xABF2);
  159. extern pascal OSErr GetThreadCurrentTaskRef(ThreadTaskRef *threadTRef)
  160.  THREEWORDINLINE(0x303C, 0x020E, 0xABF2);
  161. extern pascal OSErr GetThreadStateGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
  162.  THREEWORDINLINE(0x303C, 0x060F, 0xABF2);
  163. extern pascal OSErr SetThreadReadyGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToSet)
  164.  THREEWORDINLINE(0x303C, 0x0410, 0xABF2);
  165.  
  166. #ifdef __CFM68K__
  167. #pragma lib_export off
  168. #endif
  169.  
  170. #if GENERATINGPOWERPC
  171. #pragma options align=reset
  172. #endif
  173.  
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177.  
  178. #endif /* __THREADS__ */
  179.